/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import dao.NguoidungDAO;
import dao.SanphamDAO;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import pojo.Nguoidung;

/**
 *
 * @author kydrenw
 */
public class ThongKeController implements Controller {

    @Override
    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {

        hsr1.setCharacterEncoding("UTF-8");
        
        Nguoidung nguoiDung =(Nguoidung) hsr.getSession().getAttribute("nguoiDung");
        if (nguoiDung==null || !NguoidungDAO.laQuanLy(nguoiDung.getTendangnhap()) ) {            
            hsr.setAttribute("tag", "no");
            return new ModelAndView("admin/index");
        }  

        List<Object[]> dsSL = SanphamDAO.laySanPhamBanChay(10);
        List<Object[]> dsDT = SanphamDAO.laySanPhamDoanhThuLon(10);
        hsr.setAttribute("dsSL", dsSL);
        hsr.setAttribute("dsDT", dsDT);
        hsr.setAttribute("tag", "thongke");
        
        
        return new ModelAndView("admin/index");
    }
}
